package com.allianz.webapps.controllers;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.allianz.webapps.https.interfaces.appOpen.AppOpen;
import com.allianz.webapps.https.interfaces.appOpen.pojo.AppOpenBody;
import com.allianz.webapps.https.interfaces.type001.pojo.User;
import com.allianz.webapps.https.interfaces.util.HttpsUtil;
import com.fasterxml.jackson.core.JsonProcessingException;



@Controller
@RequestMapping("main")
public class AppOpenController {

	@Autowired
	private AppOpen appOpen;
	@RequestMapping("appopen")
	@ResponseBody
	public String appOpen(HttpServletRequest request,
			HttpServletResponse response) throws JsonProcessingException,
			Exception {
		String jsonParam = request.getParameter("jsonParam");
		Map<String,Object> map =new HashMap<String,Object>();
		User user = (User) request.getSession().getAttribute("username");
		JSONObject json = JSONObject.fromObject(jsonParam);
		AppOpenBody appOpenBody = (AppOpenBody) JSONObject.toBean(json,AppOpenBody.class);
		appOpenBody.setUser(user);
		String body = HttpsUtil.httpsPost(appOpen.requestAppOpen(appOpenBody));
		return body;
	}
}
